var tracker = null;
//全局变量，用来记录shape坐标信息
var shapeDic = {};
var layerId = "globeDrawerDemoLayer";
var drawBackFun = null;

function initDrawHelper() {
    tracker = new GlobeTracker(viewer);
    $("#drawPolygon").click(function () {
        tracker.trackPolygon(function (positions) {
            drawBackFunHandle(positions, "polygon");
        });
    });
    $("#drawPolyline").click(function () {
        tracker.trackPolyline(function (positions) {
            drawBackFunHandle(positions, "polyline");
        });
    });
    $("#drawRectangle").click(function () {
        tracker.trackRectangle(function (positions) {
            drawBackFunHandle(positions, "rectangle");
        });
    });
    $("#drawCircle").click(function () {
        tracker.trackCircle(function (positions) {
            drawBackFunHandle(positions, "circle");
        });
    });
    $("#drawPoint").click(function () {
        tracker.trackPoint(function (position) {
            drawBackFunHandle(position, "point");
        }, null, true);
    });
    $("#drawLabelPoint").click(function () {
        tracker.trackPoint(function (position) {
            drawBackFunHandle(position);
            layer.prompt({
                title: '请输入标注内容'
            }, function (value, index, elem) {
                tracker.clear();
                layer.close(index);
                viewer.entities.add({
                    id: getUUID(),
                    name: getUUID(),
                    position: position,
                    point: {
                        color: Cesium.Color.GREEN.withAlpha(1),
                        pixelSize: 5,
                        heightReference: Cesium.HeightReference.CLAMP_TO_GROUND,
                        outlineColor: Cesium.Color.YELLOW,
                        outlineWidth: 2,
                    },
                    label: {
                        text: value,
                        fillColor: Cesium.Color.fromCssColorString('#ff0000'),
                        font: '15px',
                        showBackground: false,
                        horizontalOrigin: Cesium.HorizontalOrigin.CENTER,
                        verticalOrigin: Cesium.VerticalOrigin.BOTTOM,
                        pixelOffset: new Cesium.Cartesian2(0, -30)
                    }
                });
            });
        }, null, true);
    });
    $("#drawBufferLine").click(function () {
        tracker.trackBufferLine(function (positions, radius) {});
    });
    $("#distance").click(function () {
        tracker.pickSpaceDistance(function (positions, rlt) { });
    });
    $("#stickDistance").click(function () {
        tracker.pickStickDistance(function (positions, rlt) { });
    });
    $("#area").click(function () {
        tracker.pickArea(function (positions, rlt) {});
    });

    $("#straightArrow").click(function () {
        tracker.trackStraightArrow(function (positions) {
            drawBackFunHandle(positions);
        });
    });
    $("#attackArrow").click(function () {
        tracker.trackAttackArrow(function (positions, custom) {
            drawBackFunHandle(positions);
        });
    });
    $("#pincerArrow").click(function () {
        tracker.trackPincerArrow(function (positions, custom) {
            drawBackFunHandle(positions);
        });
    });
}

//绘制回调
function drawBackFunHandle(positions, type) {
    if (!drawBackFun || !type) { return;}
    if (!(positions instanceof Array)) {
        positions = [positions];
    }
    var drawPoints = Cartesian3_to_WGS84Arr(positions);
    var thisResult = {
        prj: "EPSG:4326",
        type: type,
        points: drawPoints
    }
    thisResult["mode"] = "3D";
    thisResult["features"] = changeFormatToJson(thisResult.type, thisResult.points, thisResult.prj);
    var xzq = "";
    if(typeof(xzqService) != 'undefined' && typeof(xzqField) != 'undefined'){
        $.ajaxSettings.async = false;
        var params = {
            sr: 4326,
            where: "1=1",
            layers: 'visible',
            tolerance: 3,
            mapExtent: GetViewExtent().toString(),
            imageDisplay: viewer.scene.canvas.width + ',' + viewer.scene.canvas.height + ',96',
            geometry: JSON.stringify({
                "rings": [thisResult.points]
            }),
            geometryType: "esriGeometryPolygon",
            tolerance: 3,
            returnGeometry: false,
            returnFieldName: true,
            f: 'json'
        }
        $.get(xzqService + "/identify", params, function (data, status) {
            if(typeof(data) === "string"){
                data = JSON.parse(data)
            }
            if(data.results && data.results.length > 0){
                for (var i = 0 ; i < data.results.length ; i ++){
                    if(data.results[i]["attributes"][xzqField].length == 12){
                        if(xzq){
                            xzq += "，" + data.results[i]["attributes"]["XZQMC"];
                        }else{
                            xzq += "" + data.results[i]["attributes"]["XZQMC"];
                        }
                    }
                }
            }
        });
    }
    drawBackFun(thisResult.features,xzq);
}

function changeFormatToJson (geomType, geomPoints, geomPrj) {
    if (geomPrj) {
        geomPrj = (geomPrj.split(":").length == 2 && (geomPrj.split(":")[0] == "EPSG" || geomPrj.split(":")[0] == "wkid")) ? geomPrj.split(":")[1] : geomPrj;
    }
    geomPrj = Number(geomPrj);
    var geometry = null;
    switch (geomType) {
        case "point":
        case "esriGeometryPoint":
            geomType = "esriGeometryPoint";
            geometry = { x: geomPoints[0][0], y: geomPoints[0][1] }
            break;
        case "polyline":
        case "esriGeometryPolyline":
            geomType = "esriGeometryPolyline";
            geometry = {
                paths: geomPoints
            };
            break;
        case "polygon":
        case "esriGeometryPolygon":
        default:
            geomType = "esriGeometryPolygon";
            geometry = {
                rings: [geomPoints]
            };
            break;
    }
    var thisResult1 = {
        displayFieldName: "",
        fieldAliases: {},
        geometryType: geomType,
        spatialReference: {
            wkid: geomPrj,
            latestWkid: geomPrj
        },
        fields: [],
        features: [{
            attributes: {},
            geometry: geometry
        }]
    }
    return thisResult1;
}

//绑定cesiu事件
function bindGloveEvent() {
    var handler = new Cesium.ScreenSpaceEventHandler(viewer.scene.canvas);
    handler.setInputAction(function (movement) {
        var pick = viewer.scene.pick(movement.position);
        if (!pick) {
            return;
        }
        var obj = pick.id;
        if (!obj || !obj.layerId || flag == 0) {
            return;
        }
        var objId = obj.objId;
        //flag为编辑或删除标识,1为编辑，2为删除
        if (flag == 1) {
            switch (obj.shapeType) {
                case "Polygon":
                    flag = 0;
                    editPolygon(objId);
                    break;
                case "Polyline":
                    flag = 0;
                    editPolyline(objId);
                    break;
                case "Rectangle":
                    flag = 0;
                    editRectangle(objId);
                    break;
                case "Circle":
                    flag = 0;
                    editCircle(objId);
                    break;
                case "Point":
                    flag = 0;
                    editPoint(objId);
                    break;
                case "BufferLine":
                    flag = 0;
                    editBufferLine(objId);
                    break;
                case "StraightArrow":
                    flag = 0;
                    editStraightArrow(objId);
                    break;
                case "AttackArrow":
                    flag = 0;
                    editAttackArrow(objId);
                    break;
                case "PincerArrow":
                    flag = 0;
                    editPincerArrow(objId);
                    break;
                default:
                    break;
            }
        } else if (flag == 2) {
            clearEntityById(objId);
        }
    }, Cesium.ScreenSpaceEventType.LEFT_CLICK);
}

function showPolygon(objId, positions) {
    var material = Cesium.Color.fromCssColorString('#ff0').withAlpha(0.5);
    var outlineMaterial = new Cesium.PolylineDashMaterialProperty({
        dashLength: 16,
        color: Cesium.Color.fromCssColorString('#00f').withAlpha(0.7)
    });
    var outlinePositions = [].concat(positions);
    outlinePositions.push(positions[0]);
    var bData = {
        layerId: layerId,
        objId: objId,
        shapeType: "Polygon",
        polyline: {
            positions: outlinePositions,
            clampToGround: true,
            width: 2,
            material: outlineMaterial
        },
        polygon: new Cesium.PolygonGraphics({
            hierarchy: positions,
            asynchronous: false,
            material: material
        })
    };
    var entity = viewer.entities.add(bData);
}

function showPolyline(objId, positions) {
    var material = new Cesium.PolylineGlowMaterialProperty({
        glowPower: 0.25,
        color: Cesium.Color.fromCssColorString('#00f').withAlpha(0.9)
    });
    var bData = {
        layerId: layerId,
        objId: objId,
        shapeType: "Polyline",
        polyline: {
            positions: positions,
            clampToGround: true,
            width: 8,
            material: material
        }
    };
    var entity = viewer.entities.add(bData);
}

function showRectangle(objId, positions) {
    var material = Cesium.Color.fromCssColorString('#ff0').withAlpha(0.5);
    var outlineMaterial = new Cesium.PolylineDashMaterialProperty({
        dashLength: 16,
        color: Cesium.Color.fromCssColorString('#00f').withAlpha(0.7)
    });
    var rect = Cesium.Rectangle.fromCartesianArray(positions);
    var arr = [rect.west, rect.north, rect.east, rect.north, rect.east, rect.south, rect.west, rect.south, rect.west, rect.north];
    var outlinePositions = Cesium.Cartesian3.fromRadiansArray(arr);
    var bData = {
        layerId: layerId,
        objId: objId,
        shapeType: "Rectangle",
        polyline: {
            positions: outlinePositions,
            clampToGround: true,
            width: 2,
            material: outlineMaterial
        },
        rectangle: {
            coordinates: rect,
            material: material
        }
    };
    var entity = viewer.entities.add(bData);
}

function showCircle(objId, positions) {
    var material = Cesium.Color.fromCssColorString('#ff0').withAlpha(0.5);
    var outlineMaterial = new Cesium.PolylineDashMaterialProperty({
        dashLength: 16,
        color: Cesium.Color.fromCssColorString('#f00').withAlpha(0.7)
    });
    var radiusMaterial = new Cesium.PolylineDashMaterialProperty({
        dashLength: 16,
        color: Cesium.Color.fromCssColorString('#00f').withAlpha(0.7)
    });
    var pnts = tracker.circleDrawer._computeCirclePolygon(positions);
    var dis = tracker.circleDrawer._computeCircleRadius3D(positions);
    dis = (dis / 1000).toFixed(3);
    var text = dis + "km";
    var bData = {
        layerId: layerId,
        objId: objId,
        shapeType: "Circle",
        position: positions[0],
        label: {
            text: text,
            font: '16px Helvetica',
            fillColor: Cesium.Color.SKYBLUE,
            outlineColor: Cesium.Color.BLACK,
            outlineWidth: 1,
            style: Cesium.LabelStyle.FILL_AND_OUTLINE,
            //eyeOffset: new Cesium.ConstantProperty(new Cesium.Cartesian3(0, 0, -9000)),
            pixelOffset: new Cesium.Cartesian2(16, 16)
        },
        billboard: {
            image: "img/draw/circle_center.png",
            eyeOffset: new Cesium.ConstantProperty(new Cesium.Cartesian3(0, 0, -500)),
            heightReference: Cesium.HeightReference.CLAMP_TO_GROUND
        },
        polyline: {
            positions: positions,
            clampToGround: true,
            width: 2,
            material: radiusMaterial
        },
        polygon: new Cesium.PolygonGraphics({
            hierarchy: pnts,
            asynchronous: false,
            material: material
        })
    };
    var entity = viewer.entities.add(bData);

    var outlineBdata = {
        layerId: layerId,
        objId: objId,
        shapeType: "Circle",
        polyline: {
            positions: pnts,
            clampToGround: true,
            width: 2,
            material: outlineMaterial
        }
    };
    var outlineEntity = viewer.entities.add(outlineBdata);
}

function showPoint(objId, position) {
    var entity = viewer.entities.add({
        layerId: layerId,
        objId: objId,
        shapeType: "Point",
        position: position,
        billboard: {
            image: "img/draw/circle_red.png",
            eyeOffset: new Cesium.ConstantProperty(new Cesium.Cartesian3(0, 0, -500)),
            heightReference: Cesium.HeightReference.CLAMP_TO_GROUND
        }
    });
}

function showBufferLine(objId, positions, radius) {
    var buffer = tracker.bufferLineDrawer.computeBufferLine(positions, radius);
    var material = Cesium.Color.fromCssColorString('#ff0').withAlpha(0.5);
    var lineMaterial = new Cesium.PolylineDashMaterialProperty({
        dashLength: 16,
        color: Cesium.Color.fromCssColorString('#00f').withAlpha(0.7)
    });
    var bData = {
        layerId: layerId,
        objId: objId,
        shapeType: "BufferLine",
        polygon: new Cesium.PolygonGraphics({
            hierarchy: buffer,
            asynchronous: false,
            material: material
        }),
        polyline: {
            positions: positions,
            clampToGround: true,
            width: 2,
            material: lineMaterial
        }
    };
    var entity = viewer.entities.add(bData);
}

function showStraightArrow(objId, positions) {
    var material = Cesium.Color.fromCssColorString('#ff0').withAlpha(0.5);
    var outlineMaterial = new Cesium.PolylineDashMaterialProperty({
        dashLength: 16,
        color: Cesium.Color.fromCssColorString('#f00').withAlpha(0.7)
    });
    var outlinePositions = [].concat(positions);
    outlinePositions.push(positions[0]);
    var bData = {
        layerId: layerId,
        objId: objId,
        shapeType: "StraightArrow",
        polyline: {
            positions: outlinePositions,
            clampToGround: true,
            width: 2,
            material: outlineMaterial
        },
        polygon: new Cesium.PolygonGraphics({
            hierarchy: positions,
            asynchronous: false,
            material: material
        })
    };
    var entity = viewer.entities.add(bData);
}

function showAttackArrow(objId, positions) {
    var material = Cesium.Color.fromCssColorString('#ff0').withAlpha(0.5);
    var outlineMaterial = new Cesium.PolylineDashMaterialProperty({
        dashLength: 16,
        color: Cesium.Color.fromCssColorString('#f00').withAlpha(0.7)
    });
    var outlinePositions = [].concat(positions);
    outlinePositions.push(positions[0]);
    var bData = {
        layerId: layerId,
        objId: objId,
        shapeType: "AttackArrow",
        polyline: {
            positions: outlinePositions,
            clampToGround: true,
            width: 2,
            material: outlineMaterial
        },
        polygon: new Cesium.PolygonGraphics({
            hierarchy: positions,
            asynchronous: false,
            material: material
        })
    };
    var entity = viewer.entities.add(bData);
}

function showPincerArrow(objId, positions) {
    var material = Cesium.Color.fromCssColorString('#ff0').withAlpha(0.5);
    var outlineMaterial = new Cesium.PolylineDashMaterialProperty({
        dashLength: 16,
        color: Cesium.Color.fromCssColorString('#f00').withAlpha(0.7)
    });
    var outlinePositions = [].concat(positions);
    outlinePositions.push(positions[0]);
    var bData = {
        layerId: layerId,
        objId: objId,
        shapeType: "PincerArrow",
        polyline: {
            positions: outlinePositions,
            clampToGround: true,
            width: 2,
            material: outlineMaterial
        },
        polygon: new Cesium.PolygonGraphics({
            hierarchy: positions,
            asynchronous: false,
            material: material
        })
    };
    var entity = viewer.entities.add(bData);
}

function editPolygon(objId) {
    var oldPositions = shapeDic[objId];

    //先移除entity
    clearEntityById(objId);

    //进入编辑状态  
    tracker.polygonDrawer.showModifyPolygon(oldPositions, function (positions) {
        shapeDic[objId] = positions;
        showPolygon(objId, positions);
    }, function () {
        showPolygon(objId, oldPositions);
    });
}

function editPolyline(objId) {
    var oldPositions = shapeDic[objId];

    //先移除entity
    clearEntityById(objId);

    //进入编辑状态  
    tracker.polylineDrawer.showModifyPolyline(oldPositions, function (positions) {
        shapeDic[objId] = positions;
        showPolyline(objId, positions);
    }, function () {
        showPolyline(objId, oldPositions);
    });
}

function editRectangle(objId) {
    var oldPositions = shapeDic[objId];

    //先移除entity
    clearEntityById(objId);

    //进入编辑状态  
    tracker.rectDrawer.showModifyRectangle(oldPositions, function (positions) {
        shapeDic[objId] = positions;
        showRectangle(objId, positions);
    }, function () {
        showRectangle(objId, oldPositions);
    });
}

function editCircle(objId) {
    var oldPositions = shapeDic[objId];

    //先移除entity
    clearEntityById(objId);

    //进入编辑状态  
    tracker.circleDrawer.showModifyCircle(oldPositions, function (positions) {
        shapeDic[objId] = positions;
        showCircle(objId, positions);
    }, function () {
        showCircle(objId, oldPositions);
    });
}

function editPoint(objId) {
    var oldPosition = shapeDic[objId];

    //先移除entity
    clearEntityById(objId);

    //进入编辑状态  
    tracker.pointDrawer.showModifyPoint(oldPosition, function (position) {
        shapeDic[objId] = position;
        showPoint(objId, position);
    }, function () {
        showPoint(objId, oldPosition);
    });
}

function editBufferLine(objId) {
    var old = shapeDic[objId];

    //先移除entity
    clearEntityById(objId);

    //进入编辑状态  
    tracker.bufferLineDrawer.showModifyBufferLine(old.positions, old.radius, function (positions, radius) {
        shapeDic[objId] = {
            positions: positions,
            radius: radius
        };
        showBufferLine(objId, positions, radius);
    }, function () {
        showBufferLine(old.positions, old.radius, oldPositions);
    });
}

function editStraightArrow(objId) {
    var oldPositions = shapeDic[objId];

    //先移除entity
    clearEntityById(objId);

    //进入编辑状态  
    tracker.straightArrowDrawer.showModifyStraightArrow(oldPositions, function (positions) {
        shapeDic[objId] = positions;
        showStraightArrow(objId, positions);
    }, function () {
        showStraightArrow(objId, oldPositions);
    });
}

function editAttackArrow(objId) {
    var old = shapeDic[objId];

    //先移除entity
    clearEntityById(objId);

    tracker.attackArrowDrawer.showModifyAttackArrow(old.custom, function (positions, custom) {
        //保存编辑结果
        shapeDic[objId] = {
            custom: custom,
            positions: positions
        };
        showAttackArrow(objId, positions);
    }, function () {
        showAttackArrow(objId, old.positions);
    });
}

function editPincerArrow(objId) {
    var old = shapeDic[objId];

    //先移除entity
    clearEntityById(objId);

    tracker.pincerArrowDrawer.showModifyPincerArrow(old.custom, function (positions, custom) {
        //保存编辑结果
        shapeDic[objId] = {
            custom: custom,
            positions: positions
        };
        showPincerArrow(objId, positions);
    }, function () {
        showPincerArrow(objId, old.positions);
    });
}

function clearEntityById(objId) {
    var entityList = viewer.entities.values;
    if (entityList == null || entityList.length < 1) {
        return;
    }
    for (var i = 0; i < entityList.length; i++) {
        var entity = entityList[i];
        if (entity.layerId == layerId && entity.objId == objId) {
            viewer.entities.remove(entity);
            i--;
        }
    }
}

var measureHeight = function (viewer, handler) {
    RemoveAllLayers();
    var handler_g = handler = new Cesium.ScreenSpaceEventHandler(viewer.scene.canvas);
    var positions = [];
    var poly = null;
    // var tooltip = document.getElementById("toolTip");
    var tooltip = new GlobeTooltip(viewer.container);
    var height = 0;
    var cartesian = null;
    var floatingPoint;
    // tooltip.style.display = "block";

    handler.setInputAction(function (movement) {
        // tooltip.style.left = movement.endPosition.x + 3 + "px";
        // tooltip.style.top = movement.endPosition.y - 25 + "px";
        // tooltip.innerHTML = '<p>单击开始，双击结束</p>';
        var wp = movement.endPosition;
        if (!Cesium.defined(wp)) {
            return;
        }
        if (positions.length == 0) {
            tooltip.showAt(wp, "<p>单击选择起点</p>");
        }else{
            tooltip.showAt(wp, "<p>右击结束</p>");
        }
        cartesian = getPickPositionGlobe(movement.endPosition);
        if (positions.length >= 2) {
            if (!Cesium.defined(poly)) {
                poly = new PolyLinePrimitive(positions);
            } else {
                positions.pop();
                positions.push(cartesian);
            }
            height = getHeight(positions);
        }
    }, Cesium.ScreenSpaceEventType.MOUSE_MOVE);

    handler.setInputAction(function (movement) {
        // tooltip.style.display = "none";
        cartesian = getPickPositionGlobe(movement.position);

        if (positions.length == 0) {
            positions.push(cartesian.clone());
            positions.push(cartesian);

            floatingPoint_g = floatingPoint = viewer.entities.add({
                //parent: measure_entities,
                name: '高度',
                position: positions[0],
                point: {
                    pixelSize: 5,
                    color: Cesium.Color.RED,
                    outlineColor: Cesium.Color.WHITE,
                    outlineWidth: 2,
                    heightReference: Cesium.HeightReference.none
                },
                //label: {
                //    text: "0米",
                //    font: '18px sans-serif',
                //    fillColor: Cesium.Color.GOLD,
                //    style: Cesium.LabelStyle.FILL_AND_OUTLINE,
                //    outlineWidth: 2,
                //    verticalOrigin: Cesium.VerticalOrigin.BOTTOM,
                //    pixelOffset: new Cesium.Cartesian2(20, -40)
                //}
            });
        }
    }, Cesium.ScreenSpaceEventType.LEFT_CLICK);

    handler.setInputAction(function (movement) {
        handler.destroy();
        // tooltip.style.display = "none";
        var textDisance = height + "米";
        var point1cartographic = Cesium.Cartographic.fromCartesian(positions[0]);
        var point2cartographic = Cesium.Cartographic.fromCartesian(positions[1]);
        var point_temp = Cesium.Cartesian3.fromDegrees(Cesium.Math.toDegrees(point1cartographic.longitude), Cesium.Math.toDegrees(point1cartographic.latitude), point2cartographic.height);
        viewer.entities.add({
            name: '直线距离',
            position: point_temp,
            point: {
                pixelSize: 5,
                color: Cesium.Color.RED,
                outlineColor: Cesium.Color.WHITE,
                outlineWidth: 2,
                heightReference: Cesium.HeightReference.none
            },
            label: {
                text: textDisance,
                font: '18px sans-serif',
                fillColor: Cesium.Color.GOLD,
                style: Cesium.LabelStyle.FILL_AND_OUTLINE,
                outlineWidth: 2,
                verticalOrigin: Cesium.VerticalOrigin.BOTTOM,
                pixelOffset: new Cesium.Cartesian2(20, -20)
            }
        });
        tooltip.setVisible(false);
    }, Cesium.ScreenSpaceEventType.RIGHT_CLICK);

    function getHeight(_positions) {
        var cartographic = Cesium.Cartographic.fromCartesian(_positions[0]);
        var cartographic1 = Cesium.Cartographic.fromCartesian(_positions[1]);
        var height_temp = cartographic1.height - cartographic.height;
        return height_temp.toFixed(2);
    }

    var PolyLinePrimitive = (function () {
        function _(positions) {
            this.options = {
                //parent: measure_entities,
                name: '直线',
                polyline: {
                    show: true,
                    positions: [],
                    material: Cesium.Color.AQUA,
                    width: 2
                },
                ellipse: {
                    show: true,
                    // semiMinorAxis : 30.0,
                    // semiMajorAxis : 30.0,
                    // height: 20.0,
                    material: Cesium.Color.GREEN.withAlpha(0.5),
                    outline: true // height must be set for outline to display
                }
            };
            this.positions = positions;
            this._init();
        }

        _.prototype._init = function () {
            var _self = this;
            var _update = function () {
                var temp_position = [];
                temp_position.push(_self.positions[0]);
                var point1cartographic = Cesium.Cartographic.fromCartesian(_self.positions[0]);
                var point2cartographic = Cesium.Cartographic.fromCartesian(_self.positions[1]);
                var point_temp = Cesium.Cartesian3.fromDegrees(Cesium.Math.toDegrees(point1cartographic.longitude), Cesium.Math.toDegrees(point1cartographic.latitude), point2cartographic.height);
                temp_position.push(point_temp);
                return temp_position;
            };
            var _update_ellipse = function () {
                return _self.positions[0];
            };
            var _semiMinorAxis = function () {
                var point1cartographic = Cesium.Cartographic.fromCartesian(_self.positions[0]);
                var point2cartographic = Cesium.Cartographic.fromCartesian(_self.positions[1]);
                /**根据经纬度计算出距离**/
                var geodesic = new Cesium.EllipsoidGeodesic();
                geodesic.setEndPoints(point1cartographic, point2cartographic);
                var s = geodesic.surfaceDistance;
                return s;
            };
            var _height = function () {
                var height_temp = getHeight(_self.positions);
                return height_temp;
            };
            //实时更新polyline.positions
            this.options.polyline.positions = new Cesium.CallbackProperty(_update, false);
            this.options.position = new Cesium.CallbackProperty(_update_ellipse, false);
            this.options.ellipse.semiMinorAxis = new Cesium.CallbackProperty(_semiMinorAxis, false);
            this.options.ellipse.semiMajorAxis = new Cesium.CallbackProperty(_semiMinorAxis, false);
            this.options.ellipse.height = new Cesium.CallbackProperty(_height, false);
            viewer.entities.add(this.options);
        };

        return _;
    })();
}